package com.milo.concurrent.forkjoin;

import java.util.concurrent.*;

/**
 * 演示ForkJoin用法
 * @author Milo Lee
 * @date 2022-04-15 15:13
 */
public class ForkJoinTest {
 public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
  ForkJoinPool pool = new ForkJoinPool();
  //创建一个累加任务,从1到100
  AccumulateTask task = new AccumulateTask(1, 100);
  ForkJoinTask<Integer> future = pool.submit(task);
  Integer sum = future.get(1, TimeUnit.SECONDS);
  System.out.println(sum);
 }
}
